﻿using System;
using System.IO;
using System.Windows.Documents;
using System.Xml;
using ICSharpCode.SharpZipLib.Zip;

namespace FB2er
{
    static class FB2Parser
    {
        public static void LoadFB2(string fileName, FlowDocument doc)
        {
            doc.Blocks.Clear();
            using (var s = new ZipInputStream(File.OpenRead(fileName)))
            {
                s.GetNextEntry();
                var rdr = XmlReader.Create(s, new XmlReaderSettings {IgnoreWhitespace = true});
                using (rdr)
                {
                    new FB2XmlTransformer(rdr).Blocks.Subscribe(bh => doc.Blocks.Add(bh.Block()));
                }
            }
        }
    }
}
